package main

import (
	"fmt"
	"golang.org/x/net/context"
	"time"
)

func main() {
	ctx, cancelFunc := context.WithCancel(context.Background())
	go demo(ctx)
	time.Sleep(10 * time.Second)
	cancelFunc()
	time.Sleep(time.Second)
}

func demo(ctx context.Context) {
	for {
		select {
		case <-ctx.Done():
			fmt.Println("Task Done")
			return
		default:
			fmt.Println("Hello World")
			time.Sleep(time.Second)
		}
	}
}
